package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbContentCategoryMapper;
import com.bw1806.pojo.TbContentCategory;
import com.bw1806.pojo.TbContentCategoryExample;
import com.bw1806.sellergoods.service.TbContentCategoryService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbContentCategoryServiceImpl implements TbContentCategoryService {

    @Autowired
    private TbContentCategoryMapper tbContentCategoryMapper;

    @Override
    public List<TbContentCategory> findAll() {
        return tbContentCategoryMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbContentCategory> pagelist(TbContentCategory tbContentCategory,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbContentCategoryExample example=new TbContentCategoryExample();

        TbContentCategoryExample.Criteria criteria = example.createCriteria();

        if(tbContentCategory!=null){
            //if(tbContentCategory.getName()!=null && tbContentCategory.getName().length()>0){
            //    criteria.andNameLike("%"+tbContentCategory.getName()+"%");
           // }
        }

        Page<TbContentCategory> page= (Page<TbContentCategory>) tbContentCategoryMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbContentCategory tbContentCategory) {
        Long id = tbContentCategory.getId();
        if(id != null && id !=0){
            tbContentCategoryMapper.updateByPrimaryKey(tbContentCategory);
        } else{
            tbContentCategoryMapper.insert(tbContentCategory);
        }
    }

    @Override
    public TbContentCategory getById(Long id) {
        return tbContentCategoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            tbContentCategoryMapper.deleteByPrimaryKey(id);
        }
        //tbContentCategoryMapper.deletebth(ids);
    }
}
